package com.hjq.controller;

import com.hjq.pojo.Result;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CookieController{
    @GetMapping("/c1")
    public Result setCookie(HttpServletResponse response ){
        response.addCookie(new Cookie("username","hjq"));
        return Result.success();
    }
    @GetMapping("/c2")
    public Result getCookie(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName() + " = " + cookie.getValue());
        }
        return Result.success();
    }
}
